<?php 
$_SESSION[TINYMCE_UPLOAD] = 'upload/plugins/' . basename(dirname(__FILE__)) . '/';
if (!file_exists('../' . $_SESSION[TINYMCE_UPLOAD])) {
  Utils::create('../' . $_SESSION[TINYMCE_UPLOAD]);
}

$data = $orm->get('pb_ht_admin', NULL, NULL, NULL, NULL, NULL)->d;
?>
<div class="pure-form pure-form-aligned" style="padding: 10px; width: 1100px;">
  <legend>基本信息</legend>
  
  <div class="pure-control-group">
    <label>管理员登陆</label>
    <input id="user" type="text" class="pure-input-1-2" placeholder="{Login}" />
  </div>
  
  <div class="pure-control-group">
    <label>管理员密码</label>
    <input id="pass" type="password" class="pure-input-1-2" placeholder="{Password}" />
  </div>
  
  <div class="pure-control-group">
    <label>接收邮箱</label>
    <input id="email" type="text" class="pure-input-1-2" placeholder="{Email}" />
  </div>
  
  <div class="pure-control-group">
    <label>网站名</label>
    <input id="shop_name" type="text" class="pure-input-1-2" placeholder="{Shop Name}" />
  </div>
  
  <legend>联系方式</legend>
  
  <div class="pure-control-group">
    <label>谷歌地图</label>
    <input id="gmap" type="text" class="pure-input-1-2" placeholder="{Address}" />
  </div>
  
  <div class="pure-control-group">
    <label>联系方式</label>
    <label><textarea id="tinymce3"></textarea></label>
  </div>
  
  <legend>页尾</legend>
  
  <div class="pure-control-group">
    <label>&nbsp;</label>
    <label><textarea id="tinymce"></textarea></label>
  </div>
  
  <div class="pure-control-group">
    <label>&nbsp;</label>
    <button class="pure-button pure-input-1-2 pure-button-primary" onclick="submit_obj();">Save</button>
  </div>
</div>

<script type="text/javascript">
  /*<![CDATA[*/
  var __data = JSON.parse('<?php echo addslashes(json_encode($data)); ?>');
  var __file = '<?php echo addslashes($app_data->param_file); ?>';
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  
  $(function(){
    
    $('#tinymce').val(__data[0].footer);
    tinyMCE.init( {
      // General options
      mode: 'exact',
      elements: 'tinymce',
      theme: 'advanced',
      height: 500,
      width: 950,

      plugins: 'filebrowser,style,iespell,preview,media,wordcount,inlinepopups',
      // Theme options
      theme_advanced_buttons1: 'undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,|,forecolor,backcolor,|,image,media,|,preview,code',
      theme_advanced_buttons2: '',
      theme_advanced_buttons3: '',
      theme_advanced_toolbar_location: 'top',
      theme_advanced_toolbar_align: 'left',
      theme_advanced_statusbar_location: 'bottom',
      theme_advanced_resizing: true,

      file_browser_callback: 'filebrowser',

      theme_advanced_resize_horizontal: false,
      
      // Example content CSS (should be your site CSS)
      theme_advanced_font_sizes: '10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px',
    });

    $('#tinymce2').val(__data[0].membership);
    tinyMCE.init( {
      // General options
      mode: 'exact',
      elements: 'tinymce2',
      theme: 'advanced',

      plugins: 'filebrowser,style,iespell,preview,media,wordcount,inlinepopups',
      // Theme options
      theme_advanced_buttons1: 'undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,|,forecolor,backcolor,|,image,media,|,preview',
      theme_advanced_buttons2: '',
      theme_advanced_buttons3: '',
      theme_advanced_toolbar_location: 'top',
      theme_advanced_toolbar_align: 'left',
      theme_advanced_statusbar_location: 'bottom',
      theme_advanced_resizing: true,

      file_browser_callback: 'filebrowser',

      theme_advanced_resize_horizontal: false,
      
      // Example content CSS (should be your site CSS)
      theme_advanced_font_sizes: '10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px',
    });

    $('#tinymce3').val(__data[0].contact);
    tinyMCE.init( {
      // General options
      mode: 'exact',
      elements: 'tinymce3',
      theme: 'advanced',

      plugins: 'filebrowser,style,iespell,preview,media,wordcount,inlinepopups',
      // Theme options
      theme_advanced_buttons1: 'undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,|,forecolor,backcolor,|,image,media,|,preview,code',
      theme_advanced_buttons2: '',
      theme_advanced_buttons3: '',
      theme_advanced_toolbar_location: 'top',
      theme_advanced_toolbar_align: 'left',
      theme_advanced_statusbar_location: 'bottom',
      theme_advanced_resizing: true,

      file_browser_callback: 'filebrowser',

      theme_advanced_resize_horizontal: false,
      
      // Example content CSS (should be your site CSS)
      theme_advanced_font_sizes: '10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px',
    });
    
    render();
  });

  function render() {
    render_data();
  };
  
  function render_data() {
    $('#user').val(__data[0].account);
    $('#pass').val('');
    $('#email').val(__data[0].email);
    $('#shop_name').val(__data[0].shop_name);
    $('#gmap').val(__data[0].gmap);
    
    if (tinyMCE.get('tinymce')) {
      tinyMCE.get('tinymce').setContent(__data[0].footer);
    } else {
      $('#tinymce').val(__data[0].footer);
    }

    if (tinyMCE.get('tinymce3')) {
      tinyMCE.get('tinymce3').setContent(__data[0].contact);
    } else {
      $('#tinymce3').val(__data[0].contact);
    }
  };

  function submit_obj() {
    req = __data[0];
    req.account = $('#user').val();
    req.__password = $('#pass').val();
    req.email = $('#email').val();
    req.shop_name = $('#shop_name').val();
    req.gmap = $('#gmap').val();
    req.contact = tinyMCE.get('tinymce3').getContent();
    req.footer = tinyMCE.get('tinymce').getContent();
    
    Ajax.request(
      __requrl + 'submit_obj',
      'req=' + Utils.encodeURI(JSON.stringify(req)),
      function(rslt) {
        render();
      },
      null
    );
  };
  /*]]>*/
</script>